package com.atguigu.banner.controller;


import com.atguigu.banner.entity.CrmBanner;
import com.atguigu.banner.service.CrmBannerService;
import com.atguigu.commonutils.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 后台管理系统
 * </p>
 *
 * @author wyj
 * @since 2021-12-21
 */
@RestController
@RequestMapping("/banner/crmAdminBanner")
//@CrossOrigin
public class CrmBannerAdminController {
    //TODO 实现banner后台管理的前端页面
    @Autowired
    CrmBannerService bannerService;

    @ApiOperation(value = "获取Banner分页列表")
    @GetMapping("getPageList/{page}/{limit}")
    public R getPageList(@ApiParam(name = "page", value = "当前页码", required = true)
                         @PathVariable Long page,
                         @ApiParam(name = "limit", value = "每页记录数", required = true)
                         @PathVariable Long limit) {
        Page<CrmBanner> pageParam = new Page<>(page,limit);
        bannerService.page(pageParam,null);
        return R.ok().data("items",pageParam.getRecords()).data("total",pageParam.getTotal());
    }

    @ApiOperation(value = "新增Banner")
    @PostMapping("save")
    public R save(@RequestBody CrmBanner banner){
        bannerService.save(banner);
        return R.ok();
    }

    @ApiOperation(value = "获取banner")
    @GetMapping("get/{id}")
    public R getBannerById(@PathVariable("id") String id){
        CrmBanner crmBanner = bannerService.getById(id);
        return R.ok().data("item",crmBanner);
    }
    @ApiOperation(value = "修改banner")
    @PostMapping("update")
    public R updateById(@RequestBody CrmBanner banner){
        bannerService.updateById(banner);
        return R.ok();
    }

    @ApiOperation(value = "删除banner")
    @DeleteMapping("remove/{id}")
    public R removeById(@PathVariable("id") String id){
        bannerService.removeById(id);
        return R.ok();
    }


}

